<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>店面群发给指定客户</title>
	<meta name="decorator" content="default"/>
	<style type="text/css">
		body {overflow:scroll;}
		#tip-msg{
		 margin-left: 95px;
		 margin-right: 100px;
		}
		#selectCustomer{
			height: 100px;
			overflow:auto;
			border: 1px solid;
			border-color: #ccc;
			border-radius:5px;
		}
		#msgContent{
			border: 1px solid #777b12;
		}
		#customerIds{height:15px;}
	</style>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#inputForm").validate({
				submitHandler: function(form){
					var customers = $("#customerIds").val();
					if (!customers){
						showTip("请选择接收信息的客户！");
						return;
					}
					var msg = $("#msgContent").val();
					msg = msg.replace(/[\r\n]/g,"").replace(/^\s*/g,"");
					if (!msg){
						showTip("请输入要发送的内容！");
						return;
					}
					$("#msgContent").val(msg);
					var submit = function(){
						sendMessage(form, 'sms', $("#sendType").val());
		            };
		    		loginPasswordPopup(submit);
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			initSelectCustomer();
			$("#customerIds").change(function(){
				initSelectCustomer();
			});
			$("#sendBtn").click(function(){
				$("#sendType").val('true');
			});
		});
		function initSelectCustomer(){
			var sel = "";
			$("#customerIds").find("option").each(function(id,op){
				if (op.selected) {
					sel += op.text +"<br/>";
					}
			 });  
			$("#selectCustomer").html(sel);
		}
	</script>
</head>
<body>
	<div class="icon-buttons">
		<a data-role="button" data-inline="true" data-icon="back" data-iconpos="notext" href="${ctx}/expert/customerExam/${target}">返回</a>
	</div>
	<form:form id="inputForm" modelAttribute="smsStoreGroupToCustomer" action="${ctx}/sms/sendStoreGroupToCustomer/save" method="post" class="form-input">
		<tags:message content="${message}"/>
		<div class="middleCls">
			<input id="btnSubmit" data-inline="true" type="submit"  value="保存并发送"/>
			<input id="sendBtn" data-inline="true" type="submit"  value="立即发送"/>
		</div>
		<div id="tip-msg"><font color="red">提示:</font>短信默认发送的时间段为14:00~17:00之间立即发送，如果不在此时间段内，短信将被保存，在规定的时间段（14:00~17:00）自动发送。</div><br/>
		<input type="hidden" id="target" name="target" value="${target}"/>
		<input type="hidden" id="sendType" name="sendType" value="false"/>
		
		<div data-role="fieldcontain">
			<label for="customerIds">筛选客户:</label>
			<select data-native-menu="false" name="customerIds" multiple="multiple"  id="customerIds" >
				<c:forEach items="${customerList}" var="customer">
					<option value="${customer.id}" selected>${customer.name}(${customer.mobile})</option>
				</c:forEach>
			</select>	
		</div>
		<div data-role="fieldcontain">
			<label for="selectCustomer">已选客户:</label>
			<div id="selectCustomer"></div>
		</div>
		<div data-role="fieldcontain">
			<label for="msgContent">内容:</label>
			<textarea id="msgContent" name="msgContent" maxlength="256" rows="10" cols="5"></textarea>
		</div>
	</form:form>
</body>
</html>
